﻿-- The idea is to group at the end of day, executions for some instrument X and aggregate them into a unique execution [For EACH booking path]
-- you bought 123 times X and sold it 109 times. Each time at différent prices and quantities
-- The idea is to remove all those and have some unique execution on X with total size (long or short) and average price
-- When you load your book in the morning with a remaining position, you have only one line per instrument
CREATE PROCEDURE [DBOrderService.spSyntheticPosition]
	@start_date DateTime,
	@end_date DateTime,
	@booking_path Varchar(255)
AS
	--SET DATEFORMAT YMD

	--declare @longleg float;
	--select @longleg = sum(+ Quantity * Price) from DBOrderService.DBOrderExecution 
		--where Way = 'Buy' 
			--and TimeStamp>=@start_date 
			--and TimeStamp<=@end_date
			--and Path Like @booking_path;
	--declare @shortleg float;
	--select @shortleg = sum(+ Quantity * Price) from DBOrderService.DBOrderExecution 
			--where Way = 'Sell' 
			--and TimeStamp>=@start_date 
			--and TimeStamp<=@end_date
			--and Path Like @booking_path;
			
	--declare @position float;
	--select @position = @longleg - @shortleg;
	--select @position;
RETURN 0